import 'package:kmxy_base/base/base_package.dart';

abstract class SettingPageState extends BasePageState<SettingPage> {
  String ipCurrent = "";
  String version = "";
  int hotVersion = 0;

  TextEditingController controller = TextEditingController();

  bool isHotTest = false;
  bool isBaseSoTest = false;

  @override
  initData() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    version = packageInfo.version;
    ipCurrent = Net.dio.options.baseUrl;
    isHotTest = await SpUtil.getBool('isHotTest') ?? false;
    isBaseSoTest = await SpUtil.getBool('isBaseSoTest') ?? false;
    hotVersion = await getHotJson(widget.arguments?['appid'] ?? '');
    setState(() {});
  }

  /// 默认地址
  defaultIp() async {
    setState(() {
      controller.text = Net.DEFAULT_IP;
    });
  }

  /// 确认修改
  sureModify() async {
    if (controller.text.isEmpty) {
      "请填写IP地址".toast();
      return;
    }
    if (!controller.text.contains("http")) {
      controller.text = "http://${controller.text}/";
    }
    Net.dio.options.baseUrl = controller.text;
    finishPop(context);
  }

  /// 设置log按钮显示隐藏
  setLog() async {
    SpUtil.setBool(Net.IS_SHOW_LOG_BTN, !Net.isShowLogBtn);
    setState(() {
      Net.isShowLogBtn = !Net.isShowLogBtn;
    });
  }

  /// 设置测试Hot,开关
  setHot() async {
    isHotTest = !isHotTest;
    await SpUtil.setBool('isHotTest', isHotTest);
    setState(() {});
  }

  /// 设置强制更新,开关
  setBaseSo() async {
    isBaseSoTest = !isBaseSoTest;
    await SpUtil.setBool('isBaseSoTest', isBaseSoTest);
    setState(() {});
  }

  @override
  destroyData() {}
}
